package com.ayx.sprincloud.service.impl;

import com.ayx.sprincloud.service.IMessageSend;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

@EnableBinding(Source.class) //定义消息队列为提供方
@Slf4j
public class MessageSendImpl implements IMessageSend {

    @Resource
    private MessageChannel output;

    @Override
    public String sendMessage() {
        String number = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(number).build());
        log.info("消息发送成功： "+number);
        return null;
    }
}
